﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.Course;
using Telerik.WebControls;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Common.Upload;

public partial class sysadmin_CourseManager_UploadDownLoadResource : PowerCreator.LMS.Web.Base.WebBasePage
{
    Course opCourse = new Course();
    Resource objResourceManager = new Resource();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            ViewState["ResourceID"] = Request.QueryString["ResourceID"].ToString();
            ViewState["ResourceInfo"] = opCourse.LoadResource(int.Parse(ViewState["ResourceID"].ToString()));
                
            InitPage();


    
        }
    }

    protected override  void InitPage()
    {

        lbl_InfoTitle.Text = GetLanageValueByKey("lbl_UploadResource_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_Course.Text = GetLanageValueByKey("lbl_UploadResource_Course", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_ResourceType.Text = GetLanageValueByKey("lbl_UploadResource_ResourceType", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewDirectiory.Text = GetLanageValueByKey("lbl_UploadResource_NewDirectiory", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_File.Text = GetLanageValueByKey("lbl_UploadResource_File", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_UploadFile.Text = GetLanageValueByKey("btn_UploadResource_UploadFile", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_Back.Text = GetLanageValueByKey("btn_UploadResource_Back", PowerCreator.LMS.Language.LanagetItemType.Page);

        lbl_Description_title.Text = GetLanageValueByKey("lbl_UploadResource_Description_title", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_1.Text = GetLanageValueByKey("lbl_UploadResource_Description_1", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_2.Text = GetLanageValueByKey("lbl_UploadResource_Description_2", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_3.Text = GetLanageValueByKey("lbl_UploadResource_Description_3", PowerCreator.LMS.Language.LanagetItemType.Page);
        lbl_Description_4.Text = GetLanageValueByKey("lbl_UploadResource_Description_4", PowerCreator.LMS.Language.LanagetItemType.Page);

        //base.InitPage();
    }


    protected void btnUploadFile_Click(object sender, EventArgs e)
    {
        VOTResource objVOTResource = (VOTResource)ViewState["ResourceInfo"];

        btn_UploadFile.Enabled = false;
        try
        {
            string fileName=string.Empty;
            foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
            {
                string Path = Server.MapPath(WebUtils.WebRoot + "/" + objVOTResource.ResourceUrl + "/");

                //如果路径不存在，则创建
                if (System.IO.Directory.Exists(Path) == false)
                {
                    System.IO.Directory.CreateDirectory(Path);
                }

                //组合路径，file.GetName()取得文件名
                fileName = opCourse.GetUploadResourceFileName(file.GetExtension());

                Path = Path + fileName;

                //保存
                file.SaveAs(Path, true);


                //string url = "AddResourceInfo.aspx?AddResourceType=upload&CourseID=" + ddl_Course.SelectedValue.ToString() + "&SysResourceType=" + ddl_ResourceType.SelectedValue.ToString() + "&dir=" + txt_NewDirectiory.Text.ToString() + "&fileName=" + fileName + "&fullpath=" + Path;
                //Script.RedirectURL(url);
            }
            objVOTResource.ResourceDownLoadFileName = fileName;
            if (!opCourse.UpdateResource(objVOTResource))
            {
                Script.Alert(this, "msg", GetLanageValueByKey("msg_CelueSelectQuest_shuruti24", PowerCreator.LMS.Language.LanagetItemType.Page));
            }
            else
            {
                Script.Alert(this, "msg", GetLanageValueByKey("msg_CelueSelectQuest_shuruti23", PowerCreator.LMS.Language.LanagetItemType.Page));
            }
        }
        catch
        {
            Script.Alert(this,"msg",GetLanageValueByKey("msg_CelueSelectQuest_shuruti24", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "CourseResource.aspx";
        Script.RedirectURL(url);
    }

}
